<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>排班时段</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form :model="infoForm" label-width="120px" ref="editForm">
          <el-form-item label="名称：">
            <el-input placeholder="填写名称" class="name-box" size="small" v-model="infoForm.name"></el-input>
          </el-form-item>
          <el-form-item label="早起始时间：">
            <el-time-picker
                class="w-80"
                size="small"
                v-model="infoForm.moring_start"
                format="HH:mm"
                value-format="HH:mm"
                :picker-options="{
    selectableRange: '06:00:00 - 23:00:00'
  }"
                placeholder="选择时间">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="早结束时间：">
            <el-time-picker
                class="w-80"
                size="small"
                v-model="infoForm.moring_end"
                format="HH:mm"
                value-format="HH:mm"
                :picker-options="{
    selectableRange: '06:00:00 - 23:00:00'
  }"
                placeholder="选择时间">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="午起始时间：">
            <el-time-picker
                class="w-80"
                size="small"
                v-model="infoForm.afternoon_start"
                format="HH:mm"
                value-format="HH:mm"
                :picker-options="{
    selectableRange: '06:00:00 - 23:00:00'
  }"
                placeholder="选择时间">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="午结束时间：">
            <el-time-picker
                class="w-80"
                size="small"
                v-model="infoForm.afternoon_end"
                format="HH:mm"
                value-format="HH:mm"
                :picker-options="{
    selectableRange: '06:00:00 - 23:00:00'
  }"
                placeholder="选择时间">
            </el-time-picker>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定修改</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {scheduling_edit} from '@/api/admin/staffService'

export default {
  props: ['visible', 'timeOption'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      infoForm: {
        moring_start: '',
        moring_end: '',
        afternoon_start: '',
        afternoon_end: '',
        name: ''
      },
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.infoForm.moring_start = this.timeOption.moring_start
        this.infoForm.moring_end = this.timeOption.moring_end
        this.infoForm.afternoon_start = this.timeOption.afternoon_start
        this.infoForm.afternoon_end = this.timeOption.afternoon_end
        this.infoForm.name = this.timeOption.name || ''
      }
    }
  },
  created() {

  },
  methods: {
    checkEditFn() {
      let infoForm = JSON.parse(JSON.stringify(this.infoForm))
      infoForm.id = this.timeOption.id
      console.log('infoForm:', infoForm)
      scheduling_edit(infoForm).then(res => {
        console.log('res:', res)
        if (!res.code) {
          this.$message.success('操作成功')
          this.$emit('initHome')
          this.closePOpup()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 500px;
  height: 420px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
.name-box{
  width: 220px;
}
</style>


